<template>
  <div>
    <div v-show="showActiveContextPage" class="root">
      <van-nav-bar class="navBar" title="发布活动" left-arrow />
      <div class="root-title"><div>活动信息</div></div>
      <div class="content">
        <van-form
          class="van-form"
          label-width="130px"
          input-align="right"
          error-message-align="right"
        >
          <van-cell-group
            style="display: flex; justify-content: space-between"
            @click="showPopup"
          >
            <div class="img-icon-box">
              <img class="img-icon" src="../../assets/类别.png" alt="" />
            </div>

            <van-cell
              is-link
              title="活动类型"
              :value="
                formGetObj.activesValue ? formGetObj.activesValue : '请选择'
              "
            />
          </van-cell-group>
          <van-popup v-model="activesPopSelectShow" round position="bottom">
            <van-picker
              @cancel="closePop"
              @confirm="getActiveValueFun"
              title="类别选择"
              show-toolbar
              :columns="formObj.activesList"
            />
          </van-popup>
          <div style="display: flex">
            <div class="img-icon-box">
              <img class="img-icon" src="../../assets/标题.png" alt="" />
            </div>
            <van-field
              :maxlength="32"
              input-align="right"
              v-model="formGetObj.title"
              label="活动标题"
              placeholder="请输入活动标题"
              :rules="[{ required: true, message: '请填写活动名' }]"
            />
          </div>

          <van-cell-group
            @click="isShowDetailPage"
            style="display: flex; justify-content: space-between"
          >
            <div class="img-icon-box">
              <img class="img-icon" src="../../assets/详情.png" alt="" />
            </div>
            <van-cell
              is-link
              title="活动详情"
              :value="isTrue ? '已完善' : '待完善'"
            />
          </van-cell-group>
          <van-cell-group style="display: flex; justify-content: space-between">
            <div class="img-icon-box">
              <img class="img-icon" src="../../assets/添加.png" alt="" />
            </div>
            <van-cell
              is-link
              title="添加图片(不超过4张)"
              :value="formGetObj.imageFileList.length > 0 ? '已添加' : '待添加'"
            />
          </van-cell-group>
          <van-field name="uploader">
            <template #input>
              <van-uploader
                preview-size="50px"
                :max-count="4"
                v-model="formGetObj.imageFileList"
                multiple
              />
            </template>
          </van-field>
        </van-form>
      </div>
      <div class="content-bottom">
        <div class="content-bottom-title">活动设置</div>
        <van-cell-group @click="isShowSetPeoplePage" style="display: flex">
          <div class="img-icon-box">
            <img class="img-icon" src="../../assets/类别.png" alt="" />
          </div>
          <van-cell
            is-link
            title="活动人数"
            :value="
              formGetObj.leastJoinNum != 0 && formGetObj.mostJoinNum != 0
                ? '已完善'
                : '待完善'
            "
          />
        </van-cell-group>
        <van-cell-group @click="isShowActiveTimePage" style="display: flex">
          <div class="img-icon-box">
            <img class="img-icon" src="../../assets/类别.png" alt="" />
          </div>
          <van-cell
            is-link
            title="活动时间"
            :value="
              formGetObj.beginTime != '' && formGetObj.endTime != ''
                ? '已完善'
                : '待完善'
            "
          />
        </van-cell-group>
        <van-cell-group @click="isShowAddressFun" style="display: flex">
          <div class="img-icon-box">
            <img class="img-icon" src="../../assets/类别.png" alt="" />
          </div>
          <van-cell
            is-link
            title="活动地址"
            :value="formGetObj.addressType != '' ? '已完善' : '待完善'"
          />
        </van-cell-group>
      </div>
      <div class="subMit-button">
        <div><a href="">查看活动审核规则</a></div>
        <van-button
          class="subMit-buttonIcon"
          @click="subMitButton"
          :color="
            formGetObj.activesValue != '' &&
            formGetObj.title != '' &&
            formGetObj.content != '' &&
            formGetObj.highLight != '' &&
            formGetObj.imageFileList != [] &&
            formGetObj.leastJoinNum != 0 &&
            formGetObj.mostJoinNum != 0 &&
            formGetObj.beginTime != '' &&
            formGetObj.endTime != '' &&
            formGetObj.addressType != ''
              ? '#f3b361'
              : '#b5b5b5'
          "
          native-type="submit"
          >提交</van-button
        >
      </div>
    </div>
    <!-- //活动详情组件 -->
    <Detail
      @activeFormRuleTrue="activeFormRuleTrueEmit"
      @scene-change="sceneChangeFun"
      v-show="showActiveDetailPop"
    ></Detail>
    <!-- //人数设置组件 -->
    <activePeopleCount
      @setPeopleRuleSuccess="setPeopleRuleSuccessFun"
      @setPeopleSceneChange="setPeopleSceneChangeFun"
      ref="setPeopleRef"
      v-show="showPeopleSet"
    ></activePeopleCount>
    <!-- 时间组件 -->
    <activeTime
      @setTimeSceneChange="setTimeSceneChangeFun"
      @setActiveRuleSuccess="setActiveRuleSuccessFun"
      v-show="activeTimePageShow"
    ></activeTime>
    <!-- 地址填写组件 -->
    <activeAddress
      @setAddressSceneChange="setAddressSceneChangeFun"
      @setAddressRuleSuccess="setAddressRuleSuccessFUn"
      v-show="addressShow"
    ></activeAddress>
  </div>
</template>
<script>
import activePeopleCount from "./component/activePeopleCount.vue";
import Detail from "./component/detail.vue";
import activeTime from "./component/activeTime.vue";
import { getActivityInfo } from "@/api/index";

import activeAddress from "./component/activeAddress.vue";
//消息提示
import { Notify } from "vant";

export default {
  name: "Page1",
  components: {
    Detail,
    activePeopleCount,
    activeTime,
    activeAddress,
  },

  data() {
    return {
      //表单内组件要显示的死数据
      formObj: {
        //级联选择器活动种类数据
        activesList: ["学习", "旅行", "运动", "休闲娱乐", "聚会", "其他"],
      },
      //表单内组件内通过操作得到的数据
      formGetObj: {
        //级联选择器选中的活动类型值
        activesValue: "",
        //活动标题
        title: "",
        //活动详情
        content: "",
        //活动亮点
        highLight: "",
        //上传的图片列表数组
        imageFileList: [],
        //最小人数
        leastJoinNum: 0,
        //最大人数
        mostJoinNum: 0,
        //活动开始时间年-月-日-时-分格式
        beginTime: "",
        //活动结束时间年-月-日-时-分格式
        endTime: "",
        //线上线下
        addressType: 2,
        //线下的地址
        areaAddress: "",
        addressSmall: "",
      },
      //活动详情页是否校验成功变量
      isTrue: false,
      //活动类型选择pop显示隐藏
      activesPopSelectShow: false,
      //-------------------------活动信息页面显示隐藏
      showActiveContextPage: true,
      //活动详情显示隐藏
      showActiveDetailPop: false,
      //人数设置页面显示隐藏
      showPeopleSet: false,
      //时间选择组件显示隐藏
      activeTimePageShow: false,
      //地址选择组件显示隐藏
      addressShow: false,
    };
  },

  // created() {
  //   this.getActivityInfoFun();
  // },
  methods: {
    //获取活动页面初始信息
    async getActivityInfoFun() {
      const res = await getActivityInfo();
      console.log(res);
    },
    //活动类型选择显示隐藏
    showPopup() {
      this.activesPopSelectShow = true;
    },
    //活动详情显示函数
    isShowDetailPage() {
      this.showActiveDetailPop = true;
      this.showActiveContextPage = false;
    },
    //接受Detail组件的场景值
    sceneChangeFun(scene) {
      this.showActiveDetailPop = scene.ruleOk;
      this.showActiveContextPage = !scene.ruleOk;
    },
    //级联组件确定拿到活动
    getActiveValueFun(e) {
      //拿到的是选择的活动值
      this.formGetObj.activesValue = e;
      //取消弹层
      this.activesPopSelectShow = false;
    },
    //级联组件取消
    closePop() {
      this.activesPopSelectShow = false;
    },
    //监听活动详情页的校验成功事件
    activeFormRuleTrueEmit(obj) {
      console.log(obj);

      this.isTrue = obj.ruleOk;
      this.formGetObj.content = obj.activeContext;
      this.formGetObj.highLight = obj.activeLight;
    },
    //点击显示人数设置页面
    isShowSetPeoplePage() {
      this.showPeopleSet = true;
      this.showActiveContextPage = false;
    },
    //监听人数设置传递的场景变化
    setPeopleSceneChangeFun() {
      this.showPeopleSet = false;
      this.showActiveContextPage = true;
    },
    //监听人数设置组件校验成功得到的函数
    setPeopleRuleSuccessFun(obj) {
      this.showPeopleSet = false;
      this.showActiveContextPage = true;

      this.formGetObj.leastJoinNum = obj.minuser;
      this.formGetObj.mostJoinNum = obj.maxuser;
    },
    //显示时间选择组件函数
    isShowActiveTimePage() {
      this.activeTimePageShow = true;

      this.showActiveContextPage = false;
    },
    //监听活动时间组件校验成功的事件
    setActiveRuleSuccessFun(star, over) {
      this.formGetObj.beginTime = star;
      this.formGetObj.endTime = over;
      this.activeTimePageShow = false;

      this.showActiveContextPage = true;
    },
    //监听活动时间组件返回的场景变换函数
    setTimeSceneChangeFun() {
      this.activeTimePageShow = false;

      this.showActiveContextPage = true;
    },
    //点击去地址填写页面
    isShowAddressFun() {
      this.showActiveContextPage = false;
      this.addressShow = true;
    },
    //监听地址组件校验成功函数
    setAddressRuleSuccessFUn(radio, areaAddress, addressSmall) {
      //判断是线上还是线下，线上没地址
      if (areaAddress) {
        this.formGetObj.areaAddress = areaAddress;
        this.formGetObj.addressSmall = addressSmall;
      }
      this.showActiveContextPage = true;
      this.addressShow = false;
      this.formGetObj.addressType = radio;
    },
    //监听地址组件返回函数
    setAddressSceneChangeFun() {
      this.showActiveContextPage = true;
      this.addressShow = false;
    },
    //提交按钮校验
    subMitButton() {
      const flag =
        this.formGetObj.activesValue != "" &&
        this.formGetObj.title != "" &&
        this.formGetObj.content != "" &&
        this.formGetObj.highLight != "" &&
        this.formGetObj.imageFileList != [] &&
        this.formGetObj.leastJoinNum != 0 &&
        this.formGetObj.mostJoinNum != 0 &&
        this.formGetObj.beginTime != "" &&
        this.formGetObj.endTime != "" &&
        this.formGetObj.addressType != ""
          ? true
          : false;
      if (flag) {
        Notify({ type: "success", message: "设置成功" });
      } else {
        Notify({ type: "danger", message: "有活动信息待完善" });

        return;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.root {
  width: 750px;
  height: 1993px;
  margin: 0 auto;
  font-size: 30px;
}
.navBar {
  height: 99px;
  font-size: 30px;
}
.root-title {
  display: flex;
  justify-content: start;
  align-items: center;
  box-sizing: border-box;
  width: 750px;
  height: 106px;
  padding-left: 27px;
  background-color: #f7f7f7;
  font-weight: R;

  font-size: 30px;
}

.content {
  height: 640px;
  margin: 0 auto;
  display: flex;
  justify-content: left;
  align-content: center;
  font-size: 34px;
}

.content-bottom {
  width: 750px;
  height: 424px;
  margin: 0 auto;
  font-size: 30px;

  margin-top: 30px;
  background-color: white;
}

.img-icon-box {
  width: 60px;
  height: 50px;
  border-radius: 3px 3px 3px 3px;
  background: #ffce7f;
  margin: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.img-icon {
  width: 30px;
  height: 30px;
}

.content-bottom-title {
  display: flex;
  justify-content: start;
  align-items: center;
  box-sizing: border-box;
  width: 750px;
  height: 106px;
  padding-left: 27px;
  background-color: #f7f7f7;
  font-weight: R;
  font-size: 30px;
  margin-top: 52px;
}
.subMit-button {
  margin: 0 auto;
  height: 173px;
  width: 323px;
  margin-top: 200px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: space-between;
}
.subMit-buttonIcon {
  display: block;
  margin: 0 auto;
  width: 323px;
  height: 92px;
}
</style>
